package com.xyebank.ledger.service.jryzadd.dataProvider.credit;

import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.vo.deal.ZADDJryCashCreditVo;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class ZADDJryCreditDataProvider implements DataProvider<ZADDJryCashCreditVo> {

	@Autowired
	private ZADDJryCashCreditMapper ZaddJryCashCreditMapper;

	@Override
	public List<ZADDJryCashCreditVo> get(Integer fromIdx, Integer tarNum) {
		List<ZADDJryCashCredit> result = ZaddJryCashCreditMapper.selectByPaging(fromIdx, tarNum);
		List<ZADDJryCashCreditVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public List<ZADDJryCashCreditVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {

		List<ZADDJryCashCredit> result = ZaddJryCashCreditMapper.selectByPeriod(dateStart, dateEnd, fromIdx, tarNum);
		List<ZADDJryCashCreditVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public Integer count(Date timeStart, Date timeEnd) {
		Integer num = ZaddJryCashCreditMapper.selectPeriodCount(timeStart, timeEnd);
		return num;
	}

	private List<ZADDJryCashCreditVo> convert2Vo(List<ZADDJryCashCredit> result) {
		List<ZADDJryCashCreditVo> list = new ArrayList<ZADDJryCashCreditVo>();
		for (int i = 0; i < result.size(); i++) {
			ZADDJryCashCreditVo vo = new ZADDJryCashCreditVo();
			BeanUtils.copyProperties(result.get(i), vo);
			list.add(vo);
		}
		return list;
	}

}
